/********************************************************
Project name: OOP - Home Assignment no. 3

Authors: Rami Berkovsky
         Ofir Cohen

File name: Risc.h

Purpose: This class contains the registers array, and
         is also implemented as Singleton


********************************************************/


#ifndef _RISC_H_
#define _RISC_H_

#include <iostream>
using namespace std;

// Singleton class
class Risc {
public:
    // operator []
    unsigned long &operator[] (const int &index) { return registers[index]; };                   // write operator
    const unsigned long &operator[] (const int &index) const { return registers[index]; };        // read-only operator

    static Risc &getInstance() {                       // returns an instance to the object of Interpreter
		static Risc _instance;
        return _instance;
    };

    void ZeroRegisters();                              // sets all registers to zero

    // print all registers value
    void PrintRegisters();

private:

    Risc() {                           // default constructor receiving non-arguments
        ZeroRegisters();
    };
    ~Risc() {};                        // default destructor
    Risc(const Risc &rp) {};           // override default copy-constructor to avoid
                                       // duplicating the object of the class

    // Data members
    unsigned long registers[8]; // emulates an eight registers array

};

inline void Risc::ZeroRegisters() {
    for (int i=0;i<8;i++)
        getInstance()[i] = 0;
};

inline void Risc::PrintRegisters() {
    for (int i=0;i<8;i++)
        cout << "reg" << i << " = " << getInstance()[i] << endl;
};




#endif